import { defineStore } from 'pinia';
import { genTestUserSig } from '@/utils/generateTestUserSig';

const appStore = defineStore('app', {
  state: () => ({
    // sdkAppId: '',
    // userId: '',
    roomId: '123456',
    // secretKey: '',
    userSig: '',
    audioDeviceId: '',
    videoDeviceId: '',
    cameraList: [] as any[],
    microphoneList: [] as any[],
    logs: [],
    isJoined: false,
    isPublished: false,
    isShared: false,
    remoteStreams: [] as any[],
    sdkAppId: '1400801637',
    userId: Math.random().toString(36).substring(2),
    secretKey: '1627109bea381cc197caf4849606631e89d2411a5a4f58623d3a9c71262c9fd6',
  }),
  getters: {},
  actions: {
    getUserSig() {
      return (
        this.userSig ||
        genTestUserSig({
          sdkAppId: parseInt(this.sdkAppId, 10),
          userId: this.userId,
          secretKey: this.secretKey,
        }).userSig
      );
    },
    createShareLink() {
      const userId = `Guest_${Math.floor(Math.random() * 1000000)}`;
      const { userSig } = genTestUserSig({
        sdkAppId: parseInt(this.sdkAppId, 10),
        userId,
        secretKey: this.secretKey,
      });
      const { origin } = window.location;
      const { pathname } = window.location;
      return `${origin}${pathname}#/invite?userSig=${userSig}&&SDKAppId=${this.sdkAppId}&&userId=${userId}&&roomId=${this.roomId}`;
    },
  },
});

export default appStore;
